package com.sky.Task;

import com.sky.Entity.Orders;
import com.sky.constant.MessageConstant;
import com.sky.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class OrderTask {

    @Autowired
    private OrderMapper orderMapper;

//    @Scheduled(cron = "0 * * * * ?")
    public void processOrderPayTimeOut(){

        LocalDateTime time=LocalDateTime.now().plusMinutes(-1);
        orderMapper.updatePayTimeOut(time, Orders.PENDING_PAYMENT,Orders.COMPLETED, MessageConstant.ORDER_PAY_TIME_OUT);
    }

    @Scheduled(cron = "0 52 11 * * ?")
    public void processOderNotFinish(){
        LocalDateTime time=LocalDateTime.now().plusMinutes(-60);
        orderMapper.updatePayTimeOut(time,Orders.DELIVERY_IN_PROGRESS,Orders.COMPLETED,null);
    }
}
